package com.davy.tx.utils;

import android.media.MediaRecorder;

import java.io.IOException;

public class AudioRecorder {

    private MediaRecorder mediaRecorder;
    private String outputFilePath;

    public AudioRecorder(String fileName) {
        mediaRecorder = new MediaRecorder();
        outputFilePath = fileName;
    }

    public void startRecording() throws IOException {
        mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
        mediaRecorder.setOutputFile(outputFilePath);

        mediaRecorder.prepare();
        mediaRecorder.start();
    }

    public void stopRecording() {
        mediaRecorder.stop();
        mediaRecorder.release();
    }
}
